//
//  FBProfileHeaderView.m
//  Friendsback
//
//  Created by 宋质彬 on 2018/3/5.
//  Copyright © 2018年 宋质彬. All rights reserved.
//

#import "FBProfileHeaderView.h"
#import "UserInfo.h"


@interface FBProfileHeaderView ()
@property (nonatomic , weak) UIImageView *backImageView;
@property (nonatomic , weak) UIView *gradientView;
@property (nonatomic , weak) UIImageView *headerImageView;
@property (nonatomic , weak) UIImageView *headerImageBackView;

@property (nonatomic , weak) UILabel *namelabel;
@property (nonatomic , weak) UILabel *phoneLabel;
@property (nonatomic , weak) UIButton *loginButton;
@property (nonatomic , weak) UIImageView *arrowImageView;

@property (nonatomic , assign) BOOL isUserLogin;

@property (nonatomic , weak) UIImageView *functionView;
@end

@implementation FBProfileHeaderView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self configView];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    [self configFrame];
}

- (void)refreshHerderWithUserinfo:(UserInfo *)userinfo {
    
    if ([UserManager isLogin]) {
        self.phoneLabel.text = userinfo.userPhone;
        self.loginButton.hidden = YES;
        self.phoneLabel.hidden = NO;
        
    }else{
        self.phoneLabel.text = @"";
        self.loginButton.hidden = NO;
        [self.loginButton setTitle:@"立即登录" forState:UIControlStateNormal];
        self.phoneLabel.hidden = YES;
    }
    
    [self configFrame];
}

#pragma mark - #pragma mark - action
- (void)loginButtonClick:(UIButton *)sender{
    
    
    if ([self.delegate respondsToSelector:@selector(clickLoginButtonOnMeHeardView)]) {
        [self.delegate clickLoginButtonOnMeHeardView];
    }
}

- (void)tapClick:(UITapGestureRecognizer *)tap{
    if ([self.delegate respondsToSelector:@selector(clickLoginButtonOnMeHeardView)]) {
        [self.delegate clickLoginButtonOnMeHeardView];
    }
}


#pragma mark - 配置视图
- (void)configView{

    
    self.backImageView = [JSLKitFactory jsl_imageViewWithFrame:CGRectZero imageName:@"mine_bg_wall" superView:self];
    
    
//    self.gradientView = [JSLKitFactory jsl_viewWithFrame:CGRectZero backgroundColor:nil superView:self.backImageView];
    

    
    
    self.backImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapClick:)];
    [self.backImageView addGestureRecognizer:tap];
    
    
    
    
    self.headerImageBackView = [JSLKitFactory jsl_imageViewWithFrame:CGRectZero imageName:@"" superView:self.backImageView];
//    self.headerImageBackView.backgroundColor = RGBACOLOR(255, 255, 255, 0.35);
    
    
    self.headerImageView =  [JSLKitFactory jsl_imageViewWithFrame:CGRectZero imageName:@"默认头像" superView:self.backImageView];
    
    

    
    self.phoneLabel = [JSLKitFactory jsl_labelWithFrame:CGRectZero text:@"" font:LIGHT_FONT(17) textColor:WHITE_COLOR textAlignment:NSTextAlignmentLeft SuperView:self.backImageView];
    
   
    
    
    self.loginButton = [JSLKitFactory jsl_buttonWithFrame:CGRectZero superView:self.backImageView setImage:nil setBackImage:nil font:REGULAR_FONT(17) titleColor:WHITE_COLOR backgroundColor:nil title:@"" target:self action:@selector(loginButtonClick:)];
    
    self.loginButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
}

#pragma mark - 配置坐标
- (void)configFrame{
    
    self.backImageView.frame = CGRectMake(0, 0, self.width, self.height);
    
//    self.gradientView.frame = CGRectMake(0, 0, self.backImageView.width, self.backImageView.height);
    
   
    
//    [JSLKitFactory gradientLayerWithSuperView:self.gradientView starColor:[@"#8C88FF" hexStringToColor] endColor:[@"#6A65FE" hexStringToColor] startPoint:CGPointMake(0.5, 0) endPoint:CGPointMake(0.5, 1) locations:@[@0,@1.0]];
    
    
    self.headerImageView.frame = CGRectMake(30*AutoSizeScaleXX, 56*AutoSizeScaleYY, 57*AutoSizeScaleXX, 57*AutoSizeScaleXX);
    
    CGSize phoneSize = [self.phoneLabel.text sizeWithAttributes:@{NSFontAttributeName : self.phoneLabel.font}];
    self.phoneLabel.frame = CGRectMake(self.headerImageView.right +16*AutoSizeScaleXX, 0, phoneSize.width, phoneSize.height);
    self.phoneLabel.centerY = self.headerImageView.centerY;
    
    
    CGSize loginSize = [self.loginButton.titleLabel.text sizeWithAttributes:@{NSFontAttributeName : REGULAR_FONT(17)}];
    self.loginButton.frame = CGRectMake(self.headerImageView.right +21*AutoSizeScaleXX, 0, loginSize.width, loginSize.height +30);
    self.loginButton.centerY = self.headerImageView.centerY;
    
    
//    CGSize nameSize = [self.namelabel.text sizeWithAttributes:@{NSFontAttributeName : self.namelabel.font}];
//    self.namelabel.frame = CGRectMake(self.headerImageView.right +21*AutoSizeScaleXX, 0, nameSize.width, nameSize.height);
//    self.namelabel.centerY = self.headerImageView.centerY;
}


@end
